/**
*******************************************************************************
* @file                  zynq_gpio.h
* @author                $Author: Xu <> $
*
* Base class for devices connected via SPI.
* Copyright 2016 RobSense. All rights reserved.
*******************************************************************************/
#ifndef _GPIO_
#define _GPIO_

#ifdef __cplusplus
extern "C" {
#endif
/***************************** Include Files *********************************/
#include "stdio.h"
#include "stdbool.h"
#include "stdint.h"
/************************** Constant Definitions *****************************/

/************************** Variable Definitions ******************************/
struct I2CDesc {
    const char *name;
    uint16_t bus;
    uint8_t _address;
};

typedef struct _I2CDevice_t{

	void (*init)(struct _I2CDevice_t *dev);
	void (*set_device_address)(struct _I2CDevice_t *dev, uint8_t address);
	void (*set_device_bus)(struct _I2CDevice_t *dev, uint8_t bus);
//	void (*set_retries)(uint8_t retries);
	bool (*transfer)(struct _I2CDevice_t dev, uint8_t *send, uint32_t send_len,
	                  uint8_t *recv, uint32_t recv_len);
	bool (*read_registers_multiple)(struct _I2CDevice_t dev, uint8_t first_reg, uint8_t *recv,
	                                 uint32_t recv_len, uint8_t times);
	bool (*set_speed)(enum Speed speed);
//	Semaphores_t *(*get_semaphore)();
	PeriodicHandle (*register_periodic_callback)(
	        uint32_t period_usec, Proc k);

	bool (*adjust_periodic_callback)(
	        PeriodicHandle h, uint32_t period_usec);
//	void (*set_split_transfers)(bool set);
	const char *_name;
	uint8_t _bus;
	uint8_t _address;
//	perf_counter_t perf;
	char *pname;

}I2CDevice_t;

typedef struct {
	I2CDevice_t (*get_device)(const char *name);
}I2CDeviceManager_t;

/************************** Function Prototypes ******************************/
void I2CDeviceManager_constructs(I2CDeviceManager_t *instance);

#ifdef __cplusplus
}
#endif
#endif
